#pragma strict
private var webcamTexture : WebCamTexture;
private var theresAError : boolean;
private var data : Color32[];
private var myTexture : Texture2D;

function Awake ()
{ 
	if (WebCamDevice == null)
	{
		return;
	}
	webcamTexture = WebCamTexture(Screen.width, Screen.height, 1);
	
	myTexture = new Texture2D (webcamTexture.width, webcamTexture.height);
	renderer.material.mainTexture = myTexture;
	
	webcamTexture.Play();

	data = new Color32[webcamTexture.width * webcamTexture.height];
}

function Update()
{
    if (webcamTexture.didUpdateThisFrame)
    {
        webcamTexture.GetPixels32(data);
       	myTexture.SetPixels32(data);
       	myTexture.Apply();
    }
}
function OnGUI ()
{
	if (theresAError)
		GUI.Label(Rect (0,0,Screen.width,Screen.height), "Camera NOT FOUND");
}
/*
private var webcamTexture : WebCamTexture;

function Start ()
{ 
	 //webcamTexture = WebCamTexture(Screen.width, Screen.height, 30);
	 webcamTexture = WebCamTexture();
	 renderer.material.mainTexture = webcamTexture;
	 webcamTexture.Play();
}*/